//
//  LVTabBarController.m
//  TourismProjects
//
//  Created by 吕惠卿 on 2017/6/28.
//  Copyright © 2017年 吕惠卿. All rights reserved.
//

#import "LVTabBarController.h"

@interface LVTabBarController ()
//{
//    NSInteger _currentIndex;
//}

@end

@implementation LVTabBarController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    HomePageViewController *firstVC = [[HomePageViewController alloc]init];
    [self addChildVC:firstVC title:@"主页" image:@"主页" selectedImage:@"主页_hover"];

    ShoppingCartViewController *enterVc = [[ShoppingCartViewController alloc]init];
    [self addChildVC:enterVc title:@"购物车" image:@"购物车-1" selectedImage:@"购物车_hover"];
    
    InformationViewController *informatVC = [[InformationViewController alloc]init];
    [self addChildVC:informatVC title:@"消息" image:@"消息" selectedImage:@"消息_hover"];
    
    MinecraftViewController *rechVC = [[MinecraftViewController alloc]init];
    [self addChildVC:rechVC title:@"我的" image:@"我的" selectedImage:@"我的_hover"];
    
    UIView *bgView = [[UIView alloc]initWithFrame:self.tabBar.bounds];
//    bgView.backgroundColor = NavColor;
    
    [self.tabBar insertSubview:bgView atIndex:0];
    self.tabBar.opaque = YES;
    
    
    UINavigationController *firstNav = [[UINavigationController alloc]initWithRootViewController:firstVC];
    UINavigationController *specialNav = [[UINavigationController alloc]initWithRootViewController:enterVc];
    UINavigationController *shopNav = [[UINavigationController alloc]initWithRootViewController:informatVC];
    UINavigationController *myNav = [[UINavigationController alloc]initWithRootViewController:rechVC];
    self.viewControllers = @[firstNav, specialNav, shopNav,myNav];
    
}

-(void)addChildVC:(UIViewController *)childVC title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    childVC.tabBarItem.title = title;//设置tabbar的文字
    
    // childVC.navigationItem.title = title;//设置navigatBar的文字、
    
    //设置子控制器的图片
    childVC.tabBarItem.image = [UIImage imageNamed:image];
    childVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //设置文字的样式
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    NSMutableDictionary * dictSelected = [NSMutableDictionary dictionary];
    dictSelected[NSForegroundColorAttributeName] = NavColor;
    
    [childVC.tabBarItem setTitleTextAttributes:dict forState:UIControlStateNormal];
    [childVC.tabBarItem setTitleTextAttributes:dictSelected forState:UIControlStateSelected];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
